﻿using Factory.EquipmentManagement.CheckMaintenanceItems;
using Factory.EquipmentManagement.CheckMaintenanceItems.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Factory.Web.Controllers.EquipmentManagement.CheckMaintenanceItems
{
    /// <summary>
    /// 点检保养项目控制器
    /// </summary>
    public class CheckMaintenanceItemController : Controller
    {
        /// <summary>
        /// 点检保养项目服务接口
        /// </summary>
        private readonly ICheckMaintenanceItemAppService _appService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="appService">点检保养项目服务接口</param>
        public CheckMaintenanceItemController(ICheckMaintenanceItemAppService appService)
        {
            _appService = appService;
        }
        /// <summary>
        /// 点检保养项目视图
        /// </summary>
        /// <returns>打开视图</returns>
        public IActionResult CheckMaintenanceItemView()
        {
            return View();
        }
        /// <summary>
        /// 添加点检保养项目服务
        /// </summary>
        /// <param name="checkMaintenanceItemDto">点检保养项目服务Dto</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Insert(CheckMaintenanceItemDto checkMaintenanceItemDto)
        {
            var reslut=await _appService.Insert(checkMaintenanceItemDto);
            return reslut;
        }
        /// <summary>
        /// 分页显示点检保养项目服务
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="itemCode">项目编号</param>
        /// <returns>返回结果</returns>
        [HttpGet]
        public async Task<JsonResult> PageList(int pageIndex, int pageSize, string? itemCode)
        {
            var list =await _appService.PageList(pageIndex, pageSize, itemCode);
            return Json(list);
        }
        /// <summary>
        /// 删除点检保养项目服务
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Deleted(string id)
        {
            var reslut=await _appService.Deleted(id);
            return reslut;
        }
        /// <summary>
        /// 编辑重复性验证
        /// </summary>
        /// <param name="itemCode">点检保养项目编码</param>
        /// <param name="id">主键</param>
        /// <returns>返回结果</returns>
        [HttpGet]
        public async Task<int> UpdateRepeatability(string itemCode, int id)
        {
            var reslut = await _appService.UpdateRepeatability(itemCode,id);
            return reslut;
        }
        /// <summary>
        /// 编辑点检保养项目服务
        /// </summary>
        /// <param name="checkMaintenanceItemDto">点检保养项目服务Dto</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Update(CheckMaintenanceItemDto checkMaintenanceItemDto)
        {
            var reslut = await _appService.Update(checkMaintenanceItemDto);
            return reslut;
        }
    }
}
